package org.epidroid.epidroid.androsoul.engine.utils;

import java.util.Iterator;

import org.epidroid.epidroid.androsoul.engine.contacts.ContactGroup;
import org.epidroid.epidroid.androsoul.engine.contacts.Contacts;
import org.epidroid.epidroid.androsoul.engine.contacts.Location;
import org.epidroid.epidroid.androsoul.engine.contacts.NetsoulContact;

import android.util.Log;

/**
 * @author conrath For debugging purpose
 */
public class Printer extends Visitor {

	private int _indent = 0;

	private void print(String t) {
		String msg = "";
		for (int i = 0; i < _indent; ++i) {
			msg += "\t";
		}
		msg += t;
		Log.v("printer", msg);
	}

	public void print(Location l) {
		print(l.getBestLocation() + " " + l.getIp());
	}

	/**
	 * Print a group of contacts
	 * 
	 * @param c
	 *            group of contacts
	 */
	public void print(ContactGroup c) {
		print(c.getName());
		_indent++;
		print(c);
		_indent--;
	}

	public void print(NetsoulContact c) {
		print(c.toString());
		_indent++;
		Iterator<Location> it = c.getLocations().iterator();
		while (it.hasNext())
			print(it.next());
		_indent--;
	}

	public void print(Contacts c) {
		Iterator<ContactGroup> it = c.iterator();
		while (it.hasNext())
			print(it.next());
	}
}
